package com.flame.system.tools.dialet;

import com.flame.system.tools.constant.GeneratorConstants;
import com.flame.system.tools.entity.JavaClassType;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class MysqlDialet implements DbDialet {

    /**
     * https://www.shuzhiduo.com/A/QW5YAEZe5m/
     */
    @Override
    public Map<String, JavaClassType> typeConvertRule() {
        Map<String, JavaClassType> map = new HashMap<>();
        map.put("TINYINT", new JavaClassType("Integer", ""));
        map.put("SMALLINT", new JavaClassType("Integer", ""));
        map.put("MEDIUMINT", new JavaClassType("Integer", ""));
        map.put("INT", new JavaClassType("Integer", ""));
        map.put("INTEGER", new JavaClassType("Integer", ""));
        map.put("BIGINT", new JavaClassType("Long", ""));
        map.put("DOUBLE", new JavaClassType("Double", ""));
        map.put("FLOAT", new JavaClassType("Float", ""));
        map.put("DECIMAL", new JavaClassType("BigDecimal", "java.math.BigDecimal"));
        map.put("CHAR", new JavaClassType("String", ""));
        map.put("VARCHAR", new JavaClassType("String", ""));
        map.put("TINYTEXT", new JavaClassType("String", ""));
        map.put("TEXT", new JavaClassType("String", ""));
        map.put("MEDIUMTEXT", new JavaClassType("String", ""));
        map.put("LONGTEXT", new JavaClassType("String", ""));
        map.put("ENUM", new JavaClassType("String", ""));
        map.put("SET", new JavaClassType("String", ""));
        map.put("DATE", new JavaClassType("Date", "java.sql.Date"));
        map.put("TIME", new JavaClassType("Time", "java.sql.Time"));
        map.put("YEAR", new JavaClassType("Date", "java.sql.Date"));
        map.put("TIMESTAMP", new JavaClassType("Timestamp", "java.sql.Timestamp"));
        map.put("DATETIME", new JavaClassType("Timestamp", "java.sql.Timestamp"));
        map.put("TINYBLOB", new JavaClassType("byte[]", ""));
        map.put("BLOB", new JavaClassType("byte[]", ""));
        map.put("MEDIUMBLOB", new JavaClassType("byte[]", ""));
        map.put("LONGBLOB", new JavaClassType("byte[]", ""));
        map.put("BINARY", new JavaClassType("byte[]", ""));
        map.put("VARBINARY", new JavaClassType("byte[]", ""));
        return map;
    }

    @Override
    public String driverClassName() {
        return "com.mysql.cj.jdbc.Driver";
    }

    @Override
    public String dbType() {
        return GeneratorConstants.MYSQL;
    }
}
